package com.tian.service;

import com.tian.dto.UserDetailReqDto;
import com.tian.dto.UserDetailRespDto;
import com.tian.entity.UserDetail;
import com.tian.enums.FlagEnum;
import com.tian.enums.ResultCode;
import com.tian.mapper.UserDetailMapper;
import com.tian.util.ResultMsgCodeEnum;
import com.tian.utils.CommonResult;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;

/**
 * @author tianwc  公众号：java后端技术全栈、面试专栏
 * @version 1.0.0
 * @date 2023年09月18日 10:26
 * 在线刷题 1200+题和1000+篇干货文章：<a href="https://woaijava.cc/">博客地址</a>
 */
@Service(version = "1.0.0")
public class UserDetailDubboServiceImpl implements UserDetailDubboService {

    @Resource
    private UserDetailMapper userDetailMapper;

    @Override
    public CommonResult addUserDetail(UserDetailReqDto userDetailReqDto) {
        // TODO: 2023/9/18 参数校验
        UserDetail userDetail = new UserDetail();
        int flag = userDetailMapper.insert(userDetail);
        if (flag == FlagEnum.SUCCESS.getFlag()) {
            return CommonResult.success();
        }
        return CommonResult.failed(ResultCode.FAILED);
    }

    @Override
    public CommonResult<UserDetailRespDto> getUserDetail(Long mainId) {
        UserDetail userDetail = userDetailMapper.selectByMainId(mainId);
        if (userDetail == null) {
            return CommonResult.failed(ResultMsgCodeEnum.PARAM_ERROR.getCode(), "参数错误");
        }
        // TODO: 2023/9/18 参数转换，把UserDetail转成UserDetailRespDto
        UserDetailRespDto userDetailRespDto = new UserDetailRespDto();
        return CommonResult.success(userDetailRespDto);
    }
}
